home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: HELP NEEDED: What the hell is wrong with my program?
- Date: 12 Jan 1996 00:44:54 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Jan11174454@qcd.lanl.gov>
- References: <4d1qmp$h43@carbon.cudenver.edu> <DTHORNTO.96Jan11125703@aplo266.spd.dsccc.com>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: dthornto@aplo266.spd.dsccc.com's message of 11 Jan 1996 18:57:03 GMT
-
- --text follows this line--
- In article <DTHORNTO.96Jan11125703@aplo266.spd.dsccc.com>
- dthornto@aplo266.spd.dsccc.com (Duane Thornton) writes:
-
- ptr-> name=(char *)malloc(strlen(str1));
-
- ^^^^^This should be strlen(str1 + 1)
- The length returned by 'strlen' does not include the terminator
- (\0). Therefore the following 'strcpy' actually copies the terminator
- outside of the memory reserved by the above 'malloc'.
-
- strlen(str1 + 1) == strlen(str1) - 1 (unless strlen(str1) == 0) :-)
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-